#include<iostream>
using namespace std;
#include "student.h"
#include "grade_analysis.h"

#include<algorithm>

//�����ܳɼ�
void Student::CalTotal()
{
	stu_total = 0.0;
	for (double i : stu_score)
	{
		stu_total += i;
	}
}

//������ѧƽ����
double GradeAnalysis::AvgMath(vector<Student>& v)
{
	double sum = 0.0, avg = 0.0;
	int cnt = 0;
	for (auto & it : v)
	{
		sum += it.GetMath();
		cnt++;
	}
	avg = sum / cnt;
	return avg;
}

//����Ӣ��ƽ����
double GradeAnalysis::AvgEn(vector<Student>& v)
{
	double sum = 0.0, avg = 0.0;
	int cnt = 0;
	for (auto & it : v)
	{
		sum += it.GetEnglish();
		cnt++;
	}
	avg = sum / cnt;
	return avg;
}

//��������ƽ����
double GradeAnalysis::AvgPol(vector<Student>& v)
{
	double sum = 0.0, avg = 0.0;
	int cnt = 0;
	for (auto & it : v)
	{
		sum += it.GetPolitics();
		cnt++;
	}
	avg = sum / cnt;
	return avg;
}

//����רҵƽ����
double GradeAnalysis::AvgPro(vector<Student>& v)
{
	double sum = 0.0, avg = 0.0;
	int cnt = 0;
	for (auto it = v.begin(); it != v.end(); ++it)
	{
		sum += (*it).GetPro();
		cnt++;
	}
	avg = sum / cnt;
	return avg;
}

//�����ܳɼ�ƽ����
double GradeAnalysis::AvgTotal(vector<Student>& v)
{
	double sum = 0.0, avg = 0.0;
	int cnt = 0;
	for (auto it = v.begin(); it != v.end(); ++it)
	{
		sum += (*it).GetTotal();
		cnt++;
	}
	avg = sum / cnt;
	return avg;
}

//ͳ�ƹҿ�����
int GradeAnalysis::FailNum(vector<Student>& v)
{
	int cnt = 0;
	for (auto it = v.begin(); it != v.end(); ++it)
	{
		if ((*it).GetMath() < 60 || (*it).GetEnglish() < 60 || (*it).GetPolitics() < 60 || (*it).GetPro() < 60)
			cnt++;
	}
	return cnt;
}

//����ҿ�������
void GradeAnalysis::OutputName(vector<Student>& v)
{
	for (auto it = v.begin(); it != v.end(); ++it)
	{
		if ((*it).GetMath() < 60 || (*it).GetEnglish() < 60 || (*it).GetPolitics() < 60 || (*it).GetPro() < 60)
			cout << (*it).GetName() << ' ';
	}
}